package com.wdc.patterns.singleton.demo7;

import java.io.Serializable;
import java.util.SplittableRandom;

public class Singleton  {

    private static boolean flag = false;
    private Singleton() {

        //多线程情况
        synchronized (Singleton.class) {
            if (flag) {
                throw new RuntimeException("不能多次创建对象");
            }
            flag = true;
        }

    }

    private static class SingletonHolder{
        private static final Singleton INSTANCE = new Singleton();
    }

    public static Singleton getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public Object readResolve() {
        return SingletonHolder.INSTANCE;
    }
}
